package com.example.njupt.uis.reservation.adapter;

import android.content.Context;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.njupt.R;
import com.example.njupt.okhttp.entity.SourceEntity;
import com.example.njupt.views.sticky.StickyQuickAdapter;
import com.example.njupt.views.sticky.StickySection;

import java.util.List;

/**
 * Author:      mwang
 * Create Date: Created in 2021/5/31 17:15
 * Update Date:
 * Modified By:
 * Description:
 */
public class SourceAdapter extends StickyQuickAdapter {

    private List<StickySection> sections;

    public SourceAdapter(Context context, List<StickySection> sections) {
        super(context);
        this.sections = sections;
    }

    @Override
    public int getGroupCount() {
        return sections == null ? 0 : sections.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        List<SourceEntity> sourceEntities = sections.get(groupPosition).getContent();
        return sourceEntities == null ? 0 : sourceEntities.size();
    }

    @Override
    public boolean hasHeader(int groupPosition) {
        return sections.get(groupPosition).isHead();
    }

    @Override
    public boolean hasFooter(int groupPosition) {
        return sections.get(groupPosition).isFoot();
    }

    @Override
    public int getHeaderLayout(int viewType) {
        return R.layout.item_source_title;
    }

    @Override
    public int getFooterLayout(int viewType) {
        return 0;
    }

    @Override
    public int getChildLayout(int viewType) {
        return R.layout.item_source;
    }

    @Override
    public void onBindHeaderViewHolder(BaseViewHolder holder, int groupPosition) {
        StickySection section = sections.get(groupPosition);
        holder.setText(R.id.tv_source_title, section.getHeadContent());
            switch (section.getHeadContent()){
                case "光学实验":
                    holder.setBackgroundResource(R.id.iv_source_title, R.mipmap.bg_light_source);
                    break;
                case "力学实验":
                    holder.setBackgroundResource(R.id.iv_source_title, R.mipmap.bg_force_source);
                    break;
                case "电学实验":
                    holder.setBackgroundResource(R.id.iv_source_title, R.mipmap.bg_electricity_source);
                    break;
                case "电子电路实验":
                    holder.setBackgroundResource(R.id.iv_source_title, R.mipmap.bg_citcuiitry_source);
                    break;
            }
    }

    @Override
    public void onBindFooterViewHolder(BaseViewHolder holder, int groupPosition) {

    }

    @Override
    public void onBindChildViewHolder(BaseViewHolder holder, int groupPosition, int childPosition) {
        SourceEntity entity = sections.get(groupPosition).getContent().get(childPosition);
        holder.setText(R.id.tv_source_name, entity.getName());
        holder.setText(R.id.tv_source_teacher_desc, entity.getTeacher());
        holder.setText(R.id.tv_source_brief, entity.getBrief());

//        holder.setVisible(R.id.iv_doing, entity.getIsDoing() == 0);
    }
}
